//
//  TSLoginCheckBox.m
//  chart
//
//  Created by 曾斌 on 16/5/1.
//  Copyright (c) 2016年 xu. All rights reserved.
//

#import "TSLoginCheckBox.h"
#import "TSCheckBox.h"
@implementation TSLoginCheckBox{
    UILabel * textLabel;
    TSCheckBox * checkBox;
}
@synthesize type;

-(instancetype)init{
    self = [super initWithFrame:CGRectMake(0, 0, 50, 10)];
    return self;
}

-(void)initUI{
    checkBox= [[TSCheckBox alloc] init];
    [checkBox initUI];
    self.contentMode = UIViewContentModeCenter;
    [self addSubview:checkBox];
    [self addSubview:[self createLabel]];
    [checkBox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
    [self initByType];
}

-(void)checkboxClick:(UIButton *)sender{
    checkBox.selected = !checkBox.selected;
        switch (type) {
            case LoginCheckBox_Remember:
                [USERDEFAULTS setBool:checkBox.selected forKey:TSUserDefaultsKey_RememberPwd];
                break;
            case LoginCheckBox_AutoLogin:
                [USERDEFAULTS setBool:checkBox.selected forKey:TSUserDefaultsKey_AutoLogin];
            
                break;
            default:
                break;
        }
    
}

-(UILabel*)createLabel{
   textLabel =  [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 50, 10)];
    [textLabel setTextColor:[UIColor whiteColor]];
    textLabel.font = FONT(10);
    return textLabel;
}

-(void)initByType{
    switch (type) {
        case LoginCheckBox_Remember:
            [textLabel setText:@"记住密码"];
             checkBox.selected = [USERDEFAULTS boolForKey:TSUserDefaultsKey_RememberPwd];
            break;
        case LoginCheckBox_AutoLogin:
             [textLabel setText:@"自动登录"];
            checkBox.selected = [USERDEFAULTS boolForKey:TSUserDefaultsKey_AutoLogin];
            break;
        default:
            break;
    }
}

-(void)setTextColor:(UIColor *)color{
    [textLabel setTextColor:color];
}
@end
